Learn how Cascading Style Sheets shape the visual language of the web: selectors, properties, layout, spacing, colors, and more.
ObjectivesBy the end of this tutorial, you will:
1. CSS Basics: Selectors, Properties, and Values (1 Hour)
CSS (Cascading Style Sheets) controls how HTML elements appear on a webpage.
A CSS rule consists of:
selector {
property: value;
}
h1 {
color: blue;
text-align: center;
}
Element Selector: Targets all instances of an element.
p {
font-size: 16px;
}
Class Selector: Targets elements with a specific class.
.highlight {
background-color: yellow;
}
HTML Example:
<p class="highlight">This is highlighted!</p>
ID Selector: Targets a specific element with an ID.
#unique {
border: 1px solid black;
}
HTML Example:
<div id="unique">Unique box</div>
Define styles directly in an elementβs style attribute.
<p style="color: red;">This text is red.</p>
Use the <style> tag in the <head> section of your HTML document.
<head>
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
Link an external CSS file using the <link> tag.
<head> <link rel="stylesheet" href="styles.css"> </head>
π Best Practice: Use external CSS for better organization and reusability.
"Let AI help you find your visual style as you explore your first styling rules."
| Tool | Use Case | Sample Prompts |
|---|---|---|
| π¬ ChatGPT | Syntax help, example code |
- "Give me a basic CSS stylesheet for a dark theme." - "Explain the difference between class and ID selectors." |
| π€ Claude | Explain selector logic, optimize code |
- "Clean up and organize this CSS code." - "Explain how specificity works in CSS selectors." |
| π Gemini | Creative layout ideas |
- "Suggest a minimal layout for a personal landing page." - "How to make a sticky header using CSS?" |
| β‘ GitHub Copilot | Suggests complete style blocks | Try typing body { or .container { and Copilot will fill values. |
| π Notion AI | Writing style guides and naming conventions | "Write a color and font style guide for my project." |
| π¨ Figma AI | Design β Code handoff previews | "Design a two-column layout and convert it to CSS." |
Goal: Create an HTML + CSS page using internal or external stylesheets.
By the end of this tutorial, you will:
CSS (Cascading Style Sheets) controls how HTML elements appear on a webpage.
selector {
property: value;
}
h1 {
color: blue;
text-align: center;
}
Element Selector: Targets all instances of an element.
p { font-size: 16px; }
Class Selector: Targets elements with a specific class.
.highlight { background-color: yellow; }
HTML Example:
<p class="highlight">This is highlighted!</p>
ID Selector: Targets a specific element by ID.
#unique { border: 1px solid black; }
<div id="unique">Unique box</div>
Inline CSS: Styles written directly in an element.
<p style="color:red;">This text is red.</p>
Internal CSS: Styles inside the <style> tag in the head.
<head>
<style>
body { font-family: Arial, sans-serif; }
</style>
</head>
External CSS: Linked stylesheet for larger projects.
<head>
<link rel="stylesheet" href="styles.css">
</head>
π Best Practice: Use external CSS for clean and reusable styles.
h1 {
color: #3498db;
background-color: #f1c40f;
}
p {
font-family: 'Arial', sans-serif;
font-size: 18px;
font-weight: bold;
}
h2 { text-align: center; }
div {
padding: 20px;
margin: 15px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
"Add rhythm to your code with colors, spacing, and some AI spark."
| Tool | Use Case | Sample Prompts |
|---|---|---|
| ChatGPT | Syntax help & style generation | "Style a card with a shadow." |
| Claude | Refactor styles | "Explain responsive padding." |
| Gemini | Modern CSS advice | "Flexible layouts with CSS." |
| Copilot | Predict class styling | Type .card { and continue. |
| Figma AI | Design β Code previews | "Design a two-column layout with CSS." |
Edit the CSS code below and click Run to see the result live!